package com.xiaoyu.lanling.feature.moment.activity

import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import com.xiaoyu.lanling.R
import com.xiaoyu.lanling.activity.base.AppCompatToolbarActivity
import com.xiaoyu.lanling.feature.moment.controller.PublishViewController

class PublishActivity : AppCompatToolbarActivity() {

    private var mController: PublishViewController? = null

    override fun onCreateSafelyAfterAppFinishInit(savedInstanceState: Bundle?) {
        super.onCreateSafelyAfterAppFinishInit(savedInstanceState)
        setLightStatusBar()
        setContentView(R.layout.moment_publish_activity)
        initToolbar()

        mController = PublishViewController(this)
    }

    override fun onDestroy() {
        super.onDestroy()
        mController?.onDestroy()
    }

    override fun onCreateOptionsMenu(menu: Menu): Boolean {
        menuInflater.inflate(R.menu.menu_more, menu)
        menu.findItem(R.id.more).title = getString(R.string.moment_publish_menu_publish)
        return super.onCreateOptionsMenu(menu)
    }

    override fun onDebounceOptionsItemSelected(item: MenuItem?): Boolean {
        if (mController?.onDebounceOptionsItemSelected(item) == true) {
            return true
        }
        return super.onDebounceOptionsItemSelected(item)
    }

    override fun onPrepareOptionsMenu(menu: Menu): Boolean {
        menu.findItem(R.id.more).isEnabled = mController?.isPublishValid() == true
        return super.onPrepareOptionsMenu(menu)
    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        mController?.onSaveInstanceState()
    }

    override fun onBackPressed() {
        mController?.onBackPressed()
    }
}